<?php
namespace app\growthArchives\controller;
use app\common\Base;
use think\Db;

class TeachingArchives extends Base {
	
	public function index() {
		return $this->fetch();
	}

	public function pageQuery() {
		$where["学期ID"] = currTerm()["termId"];
		$teacherName = input("teacherName");
		$page = input("page");
		$rows = input("rows");
		if($teacherName) $where["姓名"] = array("like",$teacherName);
		$result = Db::table('教师常规')->alias('a')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->field("a.ID,a.评价部门,a.评价类别,a.评价日期,a.教师ID,a.评价内容,a.加减分,a.学期ID,c.姓名")
				  ->where($where)
				  ->order("ID desc")
				  ->page($page, $rows)
		          ->select();
		$count = Db::table('教师常规')->alias('a')
				  ->join('教师信息 c','a.教师ID=c.ID','LEFT')
				  ->where($where)
				  ->count();
		$grid['rows'] = selectResult($result);
        $grid['total'] = $count;
		return $grid;
	}

	public function addUpdate() {
		$param = request()->param();
		try {
			if(array_key_exists("ID", $param)) {
				update('教师常规', $param);
			}else {
				$param["学期ID"] = currTerm()["termId"];
				insert('教师常规', $param);
			}
			return '000';
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return '999';
	}

	public function del() {
		$delIds = input("delIds");
		try {
			Db::name('教师常规')->where('ID','in',explode(",", $delIds))->delete();
			return "000";
		} catch (Exception $e) {
			echo $e->getMessage();
		}
		return "999";
	}

}
